package com.chcit.share.generator.controller;

import java.util.List;

import com.chcit.share.generator.model.TemplateModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.chcit.share.admin.core.http.HttpResult;
import com.chcit.share.admin.core.page.PageRequest;
import com.chcit.share.generator.service.TemplateService;

/**
 * ---------------------------
 * 模板 (TemplateController)         
 * ---------------------------
 * 作者：  liuyang
 * 时间：  2019-05-05 14:52:47
 * 说明：  我是由代码生成器生生成的
 * ---------------------------
 */
@RestController
@RequestMapping("gen/template")
public class TemplateController {

	@Autowired
	private TemplateService genTemplateService;

	/**
	 * 保存模板
	 * @param record
	 * @return
	 */	
	@PostMapping(value="/save")
	public HttpResult save(@RequestBody @Validated TemplateModel record) {
		return HttpResult.ok(genTemplateService.save(record));
	}

    /**
     * 删除模板
     * @param records
     * @return
     */
	@PostMapping(value="/delete")
	public HttpResult delete(@RequestBody List<TemplateModel> records) {
		return HttpResult.ok(genTemplateService.delete(records));
	}

    /**
     * 基础分页查询
     * @param pageRequest
     * @return
     */    
	@PostMapping(value="/findPage")
	public HttpResult findPage(@RequestBody PageRequest pageRequest) {
		return HttpResult.ok(genTemplateService.findPage(pageRequest));
	}
	
    /**
     * 根据主键查询
     * @param id
     * @return
     */ 	
	@GetMapping(value="/findById")
	public HttpResult findById(@RequestParam Long id) {
		return HttpResult.ok(genTemplateService.findById(id));
	}

	/**
	 * 查询模板和模板组的所有数据
	 * @param model
	 * @return
	 */
	@GetMapping(value="/getList")
	public HttpResult getListForTemplateAndGroup(@RequestBody TemplateModel model) {
		return HttpResult.ok(genTemplateService.selectList(model));
	}
}
